<template>
	<view class="info ph-40 mt-20">
		<u--form labelPosition="left" :model="model" ref="uForm" labelWidth="200rpx" :labelStyle="{ fontSize: 32 }">

			<u-form-item labelWidth="200rpx" label="姓名" prop="name" borderBottom>
				<u--input v-model="model.name" border="none" placeholder="请输入" fontSize="16" clearable></u--input>
			</u-form-item>
			<u-form-item labelWidth="200rpx" label="身份证号" prop="identityId" borderBottom>
				<input v-model="model.identityId" placeholder="请输入" />
			</u-form-item>
			<u-form-item labelWidth="200rpx" label="性别" prop="name" borderBottom @click="showSex = true;">
				<view class="f jc-s-b">
					<u--input v-model="model.sex" disabled disabledColor="#ffffff" placeholder="请选择" border="none"></u--input>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</u-form-item>
			<u-form-item labelWidth="200rpx" label="专业" prop="name" borderBottom @click="
              				   showSpeciality= true;

              ">
				<view class="f jc-s-b">
					<u--input v-model="model.subject" disabled disabledColor="#ffffff" placeholder="请输入" border="none"></u--input>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</u-form-item>
			<u-form-item labelWidth="200rpx" label="职称" prop="name" borderBottom @click="
            		showTitle= true;
            	
				">
				<view class="f jc-s-b">
					<u--input v-model="model.title" disabled disabledColor="#ffffff" placeholder="请输入" border="none"></u--input>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</u-form-item>
			<u-form-item labelWidth="200rpx" label="科室" prop="name" borderBottom @click="
				   showDepartment= true;

			   ">
				<view class="f jc-s-b">
					<u--input v-model="model.department" disabled disabledColor="#ffffff" placeholder="请输入"
						border="none"></u--input>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</u-form-item>
			<!-- <u-form-item
                label="毕业院校"
                prop="name"
                borderBottom
                @click="
                    showSchool = true;
                    hideKeyboard();
                "
            >
                <view class="f jc-s-b">
                    <u--input v-model="model.name" disabled disabledColor="#ffffff" placeholder="请选择" border="none"></u--input>
                    <u-icon name="arrow-right"></u-icon>
                </view>
            </u-form-item> -->
			<u-form-item labelWidth="200rpx" label="毕业院校" prop="graduated" borderBottom>
				<u--input v-model="model.graduated" border="none" placeholder="请输入" fontSize="16" clearable></u--input>
			</u-form-item>
			<u-form-item labelWidth="200rpx" label="执业编号" prop="licenseNo" borderBottom>
				<u--input v-model="model.licenseNo" border="none" placeholder="请输入" fontSize="16" clearable></u--input>
			</u-form-item>
		</u--form>

		<view :style="{ paddingBottom: safeAreaBottom + 'px' }" class="bot w-f" style="z-index: 10;">
			<view class="f ai-c ph-40 h-136 jc-s-b">
				<view class="w-327"><u-button text="取消" color="#F5F5F5" shape="circle" @click="toCancel"
						:customStyle="{ color: '#555555' }"></u-button></view>
				<view class="w-327"><u-button text="下一步" color="#FABB3C" shape="circle" @click="toNext"></u-button></view>
			</view>
		</view>
	</view>

	<!-- 性别 -->
	<u-action-sheet :show="showSex" :actions="sexList" title="请选择性别" @close="showSex = false" @select="sexSelect">
	</u-action-sheet>
	<!-- 专业 -->
	<u-action-sheet :show="showSpeciality" :actions="specialityList" title="请选择专业" @close="showSpeciality = false"
		@select="specialitySelect" name='label'> </u-action-sheet>
	<!-- 职称 -->
	<u-action-sheet :show="showTitle" :actions="titleList" title="请选择职称" @close="showTitle = false" @select="titleSelect"
		name='label'> </u-action-sheet>
	<!-- 科室 -->
	<u-action-sheet :show="showDepartment" :actions="departmentList" title="请选择科室" @close="showDepartment = false"
		@select="departmentSelect" name='label'> </u-action-sheet>
	<!-- 科室 -->
	<u-action-sheet :show="showSchool" :actions="schoolList" title="请选择毕业院校" @close="showSchool = false"
		@select="sexSelect"> </u-action-sheet>
</template>
<script setup lang="ts">
	import { ref } from 'vue';
	import { dictDataType,realNameAuth } from '@/services/api/index';

	const model = ref({});
	const showSex = ref(false);
	const showSpeciality = ref(false);
	const specialityList = ref([]);
	const showTitle = ref(false);
	const titleList = ref([]);
	const showDepartment = ref(false);
	const departmentList = ref([]);
	const showSchool = ref(false);
	const schoolList = ref([]);
	const sexList = ref([{ id: 1, name: '男' }, { id: 0, name: '女' }]);
	getDictDataType()
	function sexSelect(e : any) {
		model.value.sex = e.name;
	}
	function departmentSelect(e : any) {
		model.value.department = e.label;
	}
	function specialitySelect(e : any) {
		model.value.subject = e.label;
	}
	function titleSelect(e : any) {
		model.value.title = e.label;
	}
	
	async function toNext() {
		if (!model.value.name) {
			uni.showToast({
				title: '请输入姓名',
				icon: 'none',
			});
			return;
		}
		if (!model.value.identityId) {
			uni.showToast({
				title: '请输入身份证',
				icon: 'none',
			});
			return;
		}
		
		if (!model.value.department) {
			uni.showToast({
				title: '请选择科室',
				icon: 'none',
			});
			return;
		}
		let data={
			realName:model.value.name,
			cardNo:model.value.identityId
		}
		const res=await realNameAuth(data)
		if(res.data){
			model.value.sex = model.value.sex == '男' ? 1 : 0;
			emit('fn', model.value)
		}else{
			uni.showModal({
				icon:'none',
				title:'身份信息不匹配'
			})
		}
	
	}

	const emit = defineEmits<{
		// update:固定写法，后面的变量是父组件中v-model：后面的这个变量
		(event : 'fn', n : any) : void
	}>()
	function toCancel() {
		uni.navigateBack()
	}
	async function getDictDataType() {
		const { data } = await dictDataType({ type: 'common_doctor_dept' });
		data.forEach((item : any) => {
			item.name = item.label
		})
		departmentList.value = data;

		let res = await dictDataType({ type: 'common_doctor_subject' });
		console.log(res)
		res.data.forEach((item : any) => {
			item.name = item.label
		})
		specialityList.value = res.data;

		res = await dictDataType({ type: 'common_doctor_title' });
		res.data.forEach((item : any) => {
			item.name = item.label
		})
		titleList.value = res.data;
	}
	//底部安全距离
	const systemInfo = uni.getSystemInfoSync();
	let safeArea = systemInfo.safeArea;
	let screenHeight = systemInfo.screenHeight;
	let safeAreaBottom = screenHeight - safeArea.bottom;
</script>
<style lang="scss" scoped>
	.info {
		background: #fff;

		.bot {
			position: fixed;
			left: 0;
			bottom: 0;
			background: #fff;
			border-top: 1px solid #f5f5f5;
		}

		.upload {
			border: 1rpx solid #dddddd;
		}

		.yyzz {
			::v-deep .u-form-item__body {
				padding: 32rpx 0 !important;
				flex-direction: column !important;
			}
		}
	}
</style>